package com.lbd99.data.lbd.service;

import com.lbd99.data.lbd.dao.TInvitationMapper;
import com.lbd99.data.lbd.dao.TUserMapper;
import com.lbd99.data.lbd.vo.TInvitation;
import com.lbd99.data.lbd.vo.TUser;
import com.lbd99.data.utils.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class TInvitationService {

    @Autowired
    TInvitationMapper tInvitationMapper;
    @Autowired
    TUserMapper tUserMapper;




    public List<Map> selectList(Map<String,Object> map){
        return  tInvitationMapper.selectList(map);

    }


    public Map<String,Object> insert(int num){

        Map<String,Object> map1=new HashMap<String,Object>();

        for (int i = 0; i < num; i++) {
            TInvitation record=new TInvitation();
            record.setStatus(0);
            record.setCode("T"+ RandomUtil.getRandomNum(7));
            record.setCreateTime(new Date());
            record.setUpdateTime(new Date());
            record.setUpdateBy("-1");
            record.setCreateBy("-1");
            tInvitationMapper.insertSelective(record);
        }
        map1.put("isSuc",true);
        map1.put("msg","操作成功");

        return map1;

    }


    //**************查询推荐关系********************************

    public List<TUser> selectListTreeGrid(TUser entity) {
        List<TUser> list = selectList2(entity);
        for (TUser tUser : list) {
            if (selectCountByParentId(tUser.getId()) > 0) {
                tUser.setState("closed");
            } else {
                tUser.setState("open");
            }
          //  tUser.setTp(formatTp(adminPrivilege.getTp()));
        }
        return list;
    }

    /**
     * 查询列表数据
     */
    public List<TUser> selectList2(TUser entity2) {
        return tUserMapper.selectList2(entity2);
    }


    public int selectCountByParentId(int parentId) {
        TUser entity = new TUser();
        entity.setpId(parentId);
        return tUserMapper.selectCount2(entity);
    }
    
    
    

}
